/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
Zf2.Analisys = {
    "insertTag": function() {
        var input = $(':input[name=TAG]');
        if (Core.form.validate(input)) {
            var tagContainer = $('.recebe-tags');
            var existTag = false;
            //pega todas as tags do recebe tags
            var inputs = $('.recebe-tags input');
            inputs.each(function(i, j) {
                Core.console.debug(Zf2.Analisys.normalize($(j).val()) + " | " + Zf2.Analisys.normalize(input.val()));
                if (Zf2.Analisys.normalize($(j).val()) == Zf2.Analisys.normalize(input.val())) {
                    existTag = true;
                }

            });
            if (!existTag) {
                var html = '<div class="tag"><span class="float-left">';
                html += input.val() + '</span>';
                html += '<a class="icon-excluir" title="Excluir" href="javascript: void(0);" onclick="Zf2.Analisys.deleteTag($(this));"></a>';
                html += '<input type="hidden" value="' + input.val() + '" name="TAG_DS_DESCRICAO[]" />';
                html += '</div>';
                input.val("");
                tagContainer.append(html);
            }
        }


    },
    "deleteTag": function(element) {
        var tag = element.parent();
        tag.remove();
    },
    "normalize": function(field) {
        var from = "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ";
        var to = "aaaaeeiooouucAAAAEEIOOOUUC";

        return strtolower(strtr(field, from, to));
    },
    "searchTag": function(field) {
        $("#TAG").data("autocomplete").search($("#TAG").val());
    }


};

